﻿#ifndef LUA_H
#define LUA_H
#include <QMutex>
extern "C"{
#include<lua.h>
#include<lualib.h>
#include<lauxlib.h>
}
#include <QObject>
#include<QElapsedTimer>
#include<Windows.h>
int IsMouseButtonPressed(lua_State* L);
int GetRunningTime(lua_State* L);
int MoveMouseRelative(lua_State* L);
int IsModifierPressed(lua_State* L);
int PressKey(lua_State* L);
int ReleaseKey(lua_State* L);
int GetMousePosition(lua_State* L);
int MoveMouseTo(lua_State* L);
int PressAndReleaseMouseButton(lua_State* L);

class Lua:public QObject
{
    Q_OBJECT
public:
    Q_INVOKABLE void run();
    static Lua*& getinstance();
    inline QElapsedTimer& gettimer();
    void setcurrentgunname(QString name);
private:
    static QMutex instanceMutex;
    static Lua* instance;
    lua_State *L;
    QElapsedTimer timer;
    QStringList guns;

    QString currentgunname;
    Lua();
    ~Lua();
    Lua(const Lua&)=delete;
    Lua& operator=(const Lua&)=delete;
    class Deleter
    {
    public:
        Deleter(QMutex& Mutex);
        ~Deleter();
    private:
        QMutex& deleterMutex;
    };
    static Deleter deleter;

signals:
    void send_sens(float);
    void send_ads_sens(float);
    void send_fov(int);
    void send_cbb_1(int);
    void send_cbb_2(int);
    void send_cbb_3(int);
    void send_cbb_4(int);
    void send_cbb_5(int);
    void send_cbb_6(int);
    void sendgun(int);
    void sendscope(QString);
public slots:
    void getsetting();
    void getguns();

    void set_sens(double sens);
    void set_ads_sens(double ads_sens);
    void set_fov(int fov);
    void setcbb(int index1,int index2,int index3,int index4,int index5,int index6);
    void getguninfo();
    void getscopeinfo(QString gun);
    void changegun(WPARAM wParam, LPARAM lParam);
    void OnEvent(WPARAM wParam, LPARAM lParam);
};

#endif // Lua_H
